//
//  WalletTabHeader.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/8.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "WalletTabHeader.h"
#import "BaseTextField.h"
#import "NSString+FloatString.h"

@interface WalletTabHeader()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *info;
@property (weak, nonatomic) IBOutlet UIButton *hideSmallBtn;
@property (weak, nonatomic) IBOutlet BaseTextField *searchInput;
@property (weak, nonatomic) IBOutlet UILabel *title;

@end
@implementation WalletTabHeader

INITFROMXIB

- (void)awakeFromNib{
    [super awakeFromNib];
    [self.hideSmallBtn setTitle:[NSString stringWithFormat:@"  %@",LCLocalString(@"hide_xbz")] forState:(UIControlStateNormal)];
    self.searchInput.placeholder = [NSString stringWithFormat:@"%@..",LCLocalString(@"search")];
    self.searchInput.placeholderColor = PlhColor;
    self.searchInput.delegate = self;
    self.hideSmallBtn.titleLabel.numberOfLines = 0;
    
}

- (void)refreshWith:(WalletMainModel *)model{
    self.title.text = [NSString stringWithFormat:@"%@ BTC", [[NSString stringWithFormat:@"%@",@(model.totalBalanceToBtc)]floatString]];
    self.info.text = [NSString stringWithFormat:@"%@ USTD", [[NSString stringWithFormat:@"%@",@(model.totalBalanceToUsdt)]floatString]];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    [self performSelector:@selector(doSearch) withObject:nil afterDelay:0.05];
    return YES;
}

- (void)doSearch{
    if (self.keywordDidChangeBlock) {
        self.keywordDidChangeBlock(self.searchInput.text);
    }
}
- (IBAction)hideAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    BOOL isHide = sender.selected;
    if (self.actionBlock) {
        self.actionBlock(isHide);
    }
}

@end
